package Year21_Month12.day1206;

import java.util.Scanner;

public class ThreadDemo3 {
    public static void main(String[] args) {
        Object lock1 = new Object();
        Object lock2 = new Object();

        Thread t1 = new Thread(){
            @Override
            public void run(){
                Scanner scanner = new Scanner(System.in);
                synchronized (lock1){
                    System.out.println("请输入一个整数");
                    int num = scanner.nextInt();//如果用户不输入整数，那么就会一直阻塞在nextInt
                    System.out.println("num = " + num);
                }
            }
        };
        t1.start();
        Thread t2 = new Thread(){
            @Override
            public void run(){
                while (true){
                    synchronized (lock2){
                        System.out.println("获取到锁啦");
                        try {
                            Thread.sleep(1000);
                        }catch (InterruptedException e){
                            e.printStackTrace();
                        }
                    }
                }
            }
        };
        t2.start();

    }
}
